from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-24 14:02:20.231639
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 24, Aug, 2022
Time: 14:02:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1968
Nobs: 758.000 HQIC: -50.5349
Log likelihood: 9642.97 FPE: 9.14165e-23
AIC: -50.7466 Det(Omega_mle): 8.12450e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297900 0.055078 5.409 0.000
L1.Burgenland 0.106426 0.036570 2.910 0.004
L1.Kärnten -0.106481 0.019418 -5.484 0.000
L1.Niederösterreich 0.207275 0.076390 2.713 0.007
L1.Oberösterreich 0.110077 0.074241 1.483 0.138
L1.Salzburg 0.253371 0.039126 6.476 0.000
L1.Steiermark 0.036600 0.051031 0.717 0.473
L1.Tirol 0.106936 0.041330 2.587 0.010
L1.Vorarlberg -0.059927 0.035510 -1.688 0.091
L1.Wien 0.052533 0.065999 0.796 0.426
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063947 0.114466 0.559 0.576
L1.Burgenland -0.034372 0.076001 -0.452 0.651
L1.Kärnten 0.047313 0.040356 1.172 0.241
L1.Niederösterreich -0.175983 0.158758 -1.109 0.268
L1.Oberösterreich 0.402040 0.154291 2.606 0.009
L1.Salzburg 0.288094 0.081315 3.543 0.000
L1.Steiermark 0.105411 0.106056 0.994 0.320
L1.Tirol 0.313034 0.085895 3.644 0.000
L1.Vorarlberg 0.026639 0.073800 0.361 0.718
L1.Wien -0.028548 0.137163 -0.208 0.835
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190930 0.028305 6.745 0.000
L1.Burgenland 0.089085 0.018793 4.740 0.000
L1.Kärnten -0.008520 0.009979 -0.854 0.393
L1.Niederösterreich 0.259103 0.039258 6.600 0.000
L1.Oberösterreich 0.136934 0.038153 3.589 0.000
L1.Salzburg 0.045161 0.020107 2.246 0.025
L1.Steiermark 0.017910 0.026226 0.683 0.495
L1.Tirol 0.092636 0.021240 4.361 0.000
L1.Vorarlberg 0.058650 0.018249 3.214 0.001
L1.Wien 0.119218 0.033918 3.515 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107453 0.028740 3.739 0.000
L1.Burgenland 0.046654 0.019082 2.445 0.014
L1.Kärnten -0.014390 0.010132 -1.420 0.156
L1.Niederösterreich 0.191608 0.039860 4.807 0.000
L1.Oberösterreich 0.292594 0.038739 7.553 0.000
L1.Salzburg 0.111210 0.020416 5.447 0.000
L1.Steiermark 0.102773 0.026628 3.860 0.000
L1.Tirol 0.108875 0.021566 5.048 0.000
L1.Vorarlberg 0.069940 0.018529 3.775 0.000
L1.Wien -0.017465 0.034438 -0.507 0.612
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130154 0.052227 2.492 0.013
L1.Burgenland -0.052165 0.034677 -1.504 0.132
L1.Kärnten -0.040072 0.018413 -2.176 0.030
L1.Niederösterreich 0.169603 0.072436 2.341 0.019
L1.Oberösterreich 0.143252 0.070398 2.035 0.042
L1.Salzburg 0.287481 0.037101 7.749 0.000
L1.Steiermark 0.032722 0.048390 0.676 0.499
L1.Tirol 0.160539 0.039191 4.096 0.000
L1.Vorarlberg 0.101222 0.033673 3.006 0.003
L1.Wien 0.069260 0.062583 1.107 0.268
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057034 0.041605 1.371 0.170
L1.Burgenland 0.040442 0.027624 1.464 0.143
L1.Kärnten 0.050354 0.014668 3.433 0.001
L1.Niederösterreich 0.220007 0.057704 3.813 0.000
L1.Oberösterreich 0.286315 0.056081 5.105 0.000
L1.Salzburg 0.045006 0.029556 1.523 0.128
L1.Steiermark -0.001081 0.038549 -0.028 0.978
L1.Tirol 0.147076 0.031221 4.711 0.000
L1.Vorarlberg 0.072659 0.026824 2.709 0.007
L1.Wien 0.083100 0.049855 1.667 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180297 0.049849 3.617 0.000
L1.Burgenland -0.005626 0.033098 -0.170 0.865
L1.Kärnten -0.061377 0.017575 -3.492 0.000
L1.Niederösterreich -0.082484 0.069138 -1.193 0.233
L1.Oberösterreich 0.197655 0.067193 2.942 0.003
L1.Salzburg 0.056165 0.035412 1.586 0.113
L1.Steiermark 0.230370 0.046187 4.988 0.000
L1.Tirol 0.493587 0.037407 13.195 0.000
L1.Vorarlberg 0.047666 0.032139 1.483 0.138
L1.Wien -0.054006 0.059733 -0.904 0.366
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166293 0.057220 2.906 0.004
L1.Burgenland -0.011330 0.037992 -0.298 0.766
L1.Kärnten 0.067332 0.020173 3.338 0.001
L1.Niederösterreich 0.205216 0.079361 2.586 0.010
L1.Oberösterreich -0.066860 0.077128 -0.867 0.386
L1.Salzburg 0.210438 0.040648 5.177 0.000
L1.Steiermark 0.116241 0.053016 2.193 0.028
L1.Tirol 0.070215 0.042938 1.635 0.102
L1.Vorarlberg 0.122056 0.036892 3.309 0.001
L1.Wien 0.122050 0.068566 1.780 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361612 0.032945 10.976 0.000
L1.Burgenland 0.005984 0.021874 0.274 0.784
L1.Kärnten -0.023194 0.011615 -1.997 0.046
L1.Niederösterreich 0.213315 0.045692 4.669 0.000
L1.Oberösterreich 0.196918 0.044407 4.434 0.000
L1.Salzburg 0.044182 0.023403 1.888 0.059
L1.Steiermark -0.016423 0.030524 -0.538 0.591
L1.Tirol 0.104259 0.024722 4.217 0.000
L1.Vorarlberg 0.073341 0.021240 3.453 0.001
L1.Wien 0.041787 0.039477 1.059 0.290
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040581 0.148681 0.192776 0.157637 0.124475 0.112641 0.066037 0.223770
Kärnten 0.040581 1.000000 -0.004610 0.133087 0.040604 0.095399 0.430991 -0.052820 0.099339
Niederösterreich 0.148681 -0.004610 1.000000 0.335964 0.148681 0.298463 0.107318 0.181905 0.321107
Oberösterreich 0.192776 0.133087 0.335964 1.000000 0.227029 0.330861 0.173016 0.166884 0.262876
Salzburg 0.157637 0.040604 0.148681 0.227029 1.000000 0.146693 0.122061 0.146724 0.130189
Steiermark 0.124475 0.095399 0.298463 0.330861 0.146693 1.000000 0.150763 0.137250 0.077419
Tirol 0.112641 0.430991 0.107318 0.173016 0.122061 0.150763 1.000000 0.114740 0.151950
Vorarlberg 0.066037 -0.052820 0.181905 0.166884 0.146724 0.137250 0.114740 1.000000 0.004779
Wien 0.223770 0.099339 0.321107 0.262876 0.130189 0.077419 0.151950 0.004779 1.000000